<template>
  <div class="table-container">
    <table>
      <!-- 导航栏 -->
      <th class="navigation">
        <div>门店</div>
        <div>合计</div>
      </th>
      <th>
        <div>今日新增</div>
        <div>xxxx</div>
      </th>
      <th>
        <div>本月累计</div>
        <div>xxxx</div>
      </th>
      <th>
        <div>上月同期</div>
        <div>xxxx</div>
      </th>
      <th>
        <div>环比增长</div>
        <div>xxxx</div>
      </th>
      <th>
        <div>排名</div>
        <div>xxxx</div>
      </th>
      <!-- 表格 -->
      <tr v-for="item in data" :key="item.id">
        <td class="storeName">{{ item.storeName }}</td>
        <td>{{ item.todayNew }}</td>
        <td>{{ item.monthTotal }}</td>
        <td>{{ item.lastMonth }}</td>
        <td>{{ item.growth }}</td>
        <td>{{ item.rank }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 渲染的数据
      data: [
        {
          id: 1,
          storeName: "门店",
          todayNew: 10,
          monthTotal: 200,
          lastMonth: 150,
          growth: "+5%",
          rank: 1,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
        {
          id: 2,
          storeName: "门店",
          todayNew: 8,
          monthTotal: 180,
          lastMonth: 160,
          growth: "+3%",
          rank: 2,
        },
      ],
    };
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

/* 顶部导航 */
th {
  position: sticky;
  top: 0;
  background-color: rgb(59, 92, 255);
  z-index: 10;
}
th > div {
  position: sticky;
  top: 0;
  color: white;
  margin-bottom: 18px;
  font-weight: lighter;
  text-align: left;
}
/* 表格样式 */
.table-container {
  width: 100%;
  overflow: auto;
  height: 100vh;
}
table {
  width: 180vw;
  border-collapse: collapse;
}
th,
td {
  border-bottom: 1px solid #ddd;
  padding: 8px;
  text-align: left;
  height: 70px;
}
.storeName {
  position: sticky;
  left: 0;
  z-index: 9;
}
tr:nth-child(even) {
  background-color: #f9f9f9;
}
.table-container table tr:nth-child(odd) .storeName {
  background-color: white;
}
.table-container table tr:nth-child(even) .storeName {
  background-color: #f9f9f9;
}
.navigation {
  position: sticky;
  left: 0;
  z-index: 11;
}
tr:hover {
  background-color: #eaeaea;
}
</style>
